package saxion.speelveld.spaceengineer.controller;

import java.util.ArrayList;

import saxion.speelveld.spaceengineer.AchievementScreen;
import saxion.speelveld.spaceengineer.R;
import saxion.speelveld.spaceengineer.model.Achievement;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AchievementRowAdapter extends BaseAdapter
{

	private Activity activityContext;

	private ArrayList<Achievement> achievement;

	private static LayoutInflater inflater = null;

	private int countAccassed;

	public AchievementRowAdapter(AchievementScreen achievementScreen,
		ArrayList<Achievement> achievementList)
	{
		activityContext = achievementScreen;
		achievement = achievementList;
		inflater = (LayoutInflater) activityContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		countAccassed = 0;
	}

	@Override
	public int getCount()
	{
		return achievement.size();
	}

	@Override
	public Object getItem(int arg0)
	{
		return arg0;
	}

	@Override
	public long getItemId(int position)
	{
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		countAccassed = countAccassed + 1;

		View view = convertView;
		if (convertView == null)
		{
			view = inflater.inflate(R.layout.achievement_list_row, null);
		}

		TextView titel = (TextView) view.findViewById(R.id.achievementText);
		TextView toelichting = (TextView) view.findViewById(R.id.textView1);
		ImageView plaatje = (ImageView) view.findViewById(R.id.achievementImage);

		titel.setText(achievement.get(position).getCaption());
		toelichting.setText(achievement.get(position).getExplanation());

		// ResourceCost cost : buildings.get(position).resourceCosts

		// * Maarten: for loop niet nodig, getView word per Achievement uitgevoerd :) *//

		// for (int i = 0; i < achievement.size(); i++)
		// {
		boolean accomplished = achievement.get(position).isAccomplished();
		if (accomplished == true)
		{
			plaatje.setImageBitmap(BitmapManager.getBitmapFromResources(R.drawable.vink2,
				activityContext.getApplicationContext()));
		}
		if (accomplished == false)
		{
			plaatje.setImageBitmap(BitmapManager.getBitmapFromResources(android.R.drawable.ic_delete,
				activityContext.getApplicationContext()));
		}
		// }

		return view;
	}
}
